package com.example.hospitalsystemclient.ui.notifications;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.example.hospitalsystemclient.Dataclass.RegShortInfo;
import com.example.hospitalsystemclient.R;
import com.example.hospitalsystemclient.ui.notifications.RegViewHolder;

import java.util.List;

public class RegAdapter extends RecyclerView.Adapter<RegViewHolder> {

    private List<RegShortInfo> regList;

    public RegAdapter(List<RegShortInfo> regList) {
        this.regList = regList;
    }

    public void updateRegList(List<RegShortInfo> newRegList){
        this.regList = newRegList;
        notifyDataSetChanged();
    }

    @Override
    public RegViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_reg, parent, false);
        return new RegViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(RegViewHolder holder, int position) {
        RegShortInfo regInfo = regList.get(position);
        holder.tvDocName.setText(regInfo.getDocName());
        holder.tvRegId.setText(String.valueOf("编号："+regInfo.getRegId()));
        holder.tvOfficeName.setText("科室："+regInfo.getOfficeName());
        holder.regTime.setText("挂号时间："+regInfo.getRegTime());
        holder.appointTime.setText("预约时间："+regInfo.getAppointmentTime());

        String state = "未缴费";
        Integer stateCode = regInfo.getState();
        if(stateCode == 1) state = "已缴费";
        else if(stateCode == 2) state = "正在排队";
        else if(stateCode == 3) state = "已被挂起";
        else if(stateCode == 4) state = "正在就诊";
        holder.tvState.setText(state);
    }

    @Override
    public int getItemCount() {
        return regList.size();
    }
}